package eleven;
import java.util.ArrayList;
import java.util.Date;
public class AccountDemo {
        public static void main(String[] args)
        {
            Account p = new Account(1122,1000,"George");
            p.deposit(30,"1st deposit");
            p.deposit(40,"2nd deposit");
            p.deposit(50,"3rd deposit");
            p.withDraw(5,"1st withDraw");
            p.withDraw(4,"2nd withDraw");
            p.withDraw(2,"3rd withDraw");
            System.out.print("name :"+p.getName()+" rate: "+p.getAnnualInterestRate()+" balance: "+p.getBalance()+"\n");
            for(Transaction i:p.transactions) {
                System.out.println("date: "+i.date);
                System.out.println("type: " + i.type);
                System.out.println("amount: "+i.amount);
                System.out.println("new balance: "+i.balance);
                System.out.println("description: "+i.description);
            }
        }
    }

    class Account
    {
        private int id;
        private double balance;
        private double annualInterestRate;
        private Date dateCreated;
        private String name;
        ArrayList<Transaction> transactions;
        public Account()
        {
            this.id=0;
            this.balance=0;
            this.annualInterestRate=0;
            this.dateCreated=new Date();
            this.transactions=new ArrayList<Transaction>();
        }
        public Account(int id,double balance)
        {
            this.id=id;
            this.balance=balance;
            this.annualInterestRate=0;
            this.dateCreated=new Date();
            this.transactions=new ArrayList<Transaction>();
        }
        public Account(int id,double balance,String name)
        {
            this.id=id;
            this.balance=balance;
            this.name=name;
            this.annualInterestRate=0;
            this.dateCreated=new Date();
            this.transactions=new ArrayList<Transaction>();
        }
        public int getId(){
            return this.id;
        }
        public void setId(int id){
            this.id=id;
        }
        public double getBalance(){
            return this.balance;
        }
        public void setBalance(double balance){
           this.balance=balance;
        }
        public double getAnnualInterestRate(){
            return this.annualInterestRate;
        }
        public void setAnnualInterestRate(double x){
            this.annualInterestRate=x;
        }
        public Date getDateCreated(){
            return this.dateCreated;
        }
        public double getMonthlyInterestRate()
        {
            return this.annualInterestRate/12;
        }
        public double getMonthlyInterest(){
            return this.annualInterestRate/12*this.balance;
        }
        public void withDraw(double m,String a){
           this. balance-=m;
           this.transactions.add(new Transaction('W',m,this.balance,a));
        }
        public void deposit(double m,String a){
            balance+=m;
            this.transactions.add(new Transaction('D',m,this.balance,a));
        }
        public void setName(String name){
            this.name=name;
        }
        public String getName(){
            return this.name;
        }
    }

    class Transaction{
        public Date date;
        public char type;
        public double amount;
        public double balance;
        public String description;
        public Transaction(char type,double amount,double balance,String descrp){
            this.date=new Date();
            this.type=type;
            this.amount=amount;
            this.balance=balance;
            this.description=descrp;

        }
    }

